<?php
class QuestionModel extends Model{

	private $_tablename = "question";

	public function __construct(){}


	/**
	 * 获取最新提问列表 
	 *
	 */
	public function getRecentQuestions(){
		 $sql = "SELECT * FROM ".$this->_tablename." order by load_time DESC limit 15";
		 parent::getDb()->_db->query( $sql );
		 return parent::getDb()->_db->fetchAll(); 
	}

	/**
	 * 获取单个提问
	 */
	public function getQuestionById( $qid ){
		$sql = "SELECT * FROM ".$this->_tablename." WHERE qid = ?";
		parent::getDb()->_db->query( $sql, array( intval($qid) ) );
		return parent::getDb()->_db->fetch();
	}

	/**
	 * 获取用户提问列表 
	 *
	 */
	public function getQuestionsByUid( $uid ){
		$sql = "SELECT * FROM ".$this->_tablename." where uid = ? and status = 1 order by load_time desc";
		parent::getDb()->_db->query($sql, array( intval( $uid ) ));
		return parent::getDb()->_db->fetchAll();
	}

	/**
	 * insert database;
	 * @params options
	 * return int 1/0
	 */
	public function create( $options ){
		return parent::insert( $this->_tablename, $options );
	}

}
